import { useCountDown } from 'ahooks';
import { useEffect, useState } from 'react'


export const useTimeDown = (value: number, timeEnd: any) => {
    const [targetDate, setTargetDate] = useState<number>(0)
    const [countdown] = useCountDown({
        targetDate,
        onEnd: () => {
            timeEnd()
        },
    });

    useEffect(() => {
        setTargetDate(Date.now() + value);
    }, [])

    return [Math.round(countdown / 1000)]
}